package com.bringway.p2p.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bringway.global.util.StringUtils;
import com.bringway.p2p.dao.ZqzrshDao;
import com.bringway.p2p.dao.ZqzrsqDao;
import com.bringway.p2p.service.ZqzrService;

import net.sf.json.JSONObject;
@Service
@Transactional
public class ZqzrServiceImpl implements ZqzrService {
	Logger logger=Logger.getLogger(ZqzrServiceImpl.class);
	
	@Autowired
	private ZqzrsqDao zqzrsqDao;
	@Autowired
	private ZqzrshDao zqzrshDao;

	@Override
	public List<Map<String, Object>> queryZqzrsqList(JSONObject params) {
		return zqzrsqDao.queryZqzrsqList(params);
	}

	@Override
	public int getZqzrsqCount(JSONObject params) {
		return zqzrsqDao.getZqzrsqCount(params);
	}

	@Override
	public Map<String, Object> getZqzrsqInfo(JSONObject params) {
		return zqzrsqDao.getZqzrsqInfo(params);
	}

	@Override
	@Transactional("p2p")
	public boolean saveZqzrsh(JSONObject params) {
		/**
		 * 1.更新申请表
		 * 2.添加转让信息到zqzrlb中
		 */
		boolean isUpateZqzrsqSuc=false;
		String shzt=params.optString("shzt");
		isUpateZqzrsqSuc=zqzrsqDao.updateZqzrsq(params)>0?true:false;
		if (isUpateZqzrsqSuc) {
			logger.info("saveZqzrsh updateZqzrsq 成功!");
			if ("03".equals(shzt)) {
				logger.info("saveZqzrsh 申请表更新成,审核不通过,不添加到lb表!");
				return false;
			}
			String shid=zqzrshDao.insertZqzrsh(params);
			if (StringUtils.isNotEmpty(shid)) {
				logger.info("saveZqzrsh insertZqzrsh 成功!");
			} else {
				logger.info("saveZqzrsh insertZqzrsh 失败!");
				return false;
			}
		} else {
			logger.info("saveZqzrsh updateZqzrsq 失败!");
			return false;
		}
		
		return true;
	}

	@Override
	public boolean saveZqzrsq(JSONObject params) {
		return zqzrsqDao.insertZqzrsq(params)>0;
	}

	@Override
	public List<Map<String, Object>> queryZqzrlbList(JSONObject params) {
		return zqzrshDao.queryZqzrlbList(params);
	}

	@Override
	public int getZqzrlbCount(JSONObject params) {
		return zqzrshDao.getZqzrlbCount(params);
	}

	@Override
	public float getZqzrlbSumje(JSONObject params) {
		return zqzrshDao.getZqzrlbSumje(params);
	}

}
